package Player.IAStrategy;

import GameBoard.GameBoard;
import GameElements.Pawn;
import GameElements.Tile;
import Player.Player;

public class IAGloutonStrategy extends IAStrategy
{
	public void execute(Player player, GameBoard board)
	{
		Tile tileToPlay = board.piocher();
		Tile[][] table = board.getTable();
		
		for(int i=0 ; i< table.length; i++)
			for(int j=0 ; j< table[0].length; j++)
			{
				int nbRotation = 0;
				while(nbRotation < 4)
				{
					if(!board.canAdd(tileToPlay, i, j))
					{
						tileToPlay.rotate90();
						nbRotation++;
					}
					else
					{
						board.add(tileToPlay, i, j);
						
						//try to add a pawn
						if(player.getPawn().size() > 0)
						{
							Pawn pawn = player.takePawn(0);
							if(pawn != null)
							{
								for(int indexPawnInTile=0; indexPawnInTile<13; indexPawnInTile++)
								{								
									if(board.canAdd(pawn, i, j, indexPawnInTile))
										board.add(pawn, i, j, indexPawnInTile);
								}
							}
						}
					
						player.setPlaying(false);//fini de jouer
						return;
					}
				}
			}
	}
}
